#!/bin/sh
###################################################################################
#
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P. All rights reserved.
# import the GR global configuration files.
#  Usage: ImportGRGlobalConfig.sh $EIUM_HOME $EIUM_USER $EIUM_PWD $GR_CONFIG_FILE
#
###################################################################################
base=$(cd `dirname $0`; pwd)
base=$(echo $base | awk -F /artifacts '{print $1}')

#Please modify the following parameters for your env
if [ $# -lt 4 ]; then
  echo "Usage: ImportGRGlobalConfig.sh EIUM_HOME EIUM_USER EIUM_PWD GR_CONFIG_FILE SGR_DATA_ROOT"
  exit -1;
fi

JAVA_HOME=$JAVA_HOME

EIUM_HOME=$1
EIUM_USER=$2
EIUM_PWD=$3
GR_CONFIG_FILE=$4
SGR_DATA_ROOT=$5

VAR_ROOT_PROP="VarRoot"
INI_NAME=${EIUM_HOME}/siu_install.ini
varEIUHome=`cat $INI_NAME | grep -w $VAR_ROOT_PROP|awk -F= '{print $2}'`
secureFile=$varEIUHome/security

#echo $varEIUHome
#echo $secureFile
if [ -f "$secureFile" ];then
  $EIUM_HOME/bin/loadconfig -login $EIUM_USER -pw $EIUM_PWD -f $GR_CONFIG_FILE -merge
else
  $EIUM_HOME/bin/loadconfig -f $GR_CONFIG_FILE -merge
fi

if [ ! -d "$SGR_DATA_ROOT/bak" ];then
   mkdir $SGR_DATA_ROOT/bak
fi

SGRexportFileCount=$(ls $SGR_DATA_ROOT | grep "SGR.export" | wc -l );  
if [ $SGRexportFileCount != 0 ];then
  mv $SGR_DATA_ROOT/SGR.export*.zip $SGR_DATA_ROOT/bak
fi
